package com.example.my_music_palyer.common.tools;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * 生成正确的密码哈希值
 */
public class GenerateCorrectHash {
    
    public static void main(String[] args) {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        
        String password = "123456";
        
        System.out.println("=== 生成正确的密码哈希 ===");
        System.out.println("密码: " + password);
        
        // 生成多个哈希值进行测试
        for (int i = 1; i <= 5; i++) {
            String hash = encoder.encode(password);
            boolean isValid = encoder.matches(password, hash);
            
            System.out.println("\n哈希值 " + i + ": " + hash);
            System.out.println("验证结果: " + isValid);
            
            // 生成SQL语句
            System.out.println("SQL语句 " + i + ":");
            System.out.println("UPDATE `user` SET `password` = '" + hash + "' WHERE `username` = 'admin';");
        }
        
        // 生成一个特定的哈希值用于测试
        System.out.println("\n=== 推荐使用的哈希值 ===");
        String recommendedHash = encoder.encode(password);
        System.out.println("推荐哈希值: " + recommendedHash);
        System.out.println("验证结果: " + encoder.matches(password, recommendedHash));
        
        System.out.println("\n=== 完整的SQL更新语句 ===");
        System.out.println("-- 删除现有admin用户");
        System.out.println("DELETE FROM `user` WHERE `username` = 'admin';");
        System.out.println();
        System.out.println("-- 插入新的admin用户");
        System.out.println("INSERT INTO `user` (`username`, `password`, `role`) VALUES ('admin', '" + recommendedHash + "', 'admin');");
    }
}
